package com.xm.servlet.reception_desk.login;

import com.xm.service.reception_desk.AccountInformationService;
import com.xm.service.reception_desk.AccountService;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

/**
 * 邮箱注册
 * @author 康文程
 * @date 2023-12-25 上午 09:02
 */
@WebServlet("/mailbox/registration")
public class MailboxRegistration extends HttpServlet {
    private final AccountService service = new AccountService();
    private final AccountInformationService accountInformationService = new AccountInformationService();

    /**
     * 邮箱注册
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
        String mailbox = req.getParameter("mailbox");
        String password = req.getParameter("password");
        int id = service.addMailboxAccount(mailbox, password);
        System.out.println(id);
        resp.getWriter().println(accountInformationService.addAccountInformation(String.valueOf(UUID.randomUUID()), id));
    }
}
